package com.qding.park.adapter.test.adapter.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.qding.park.common.core.exceptions.business.adapter.AdapterException;
import com.qding.park.common.core.exceptions.system.NetWorkException;
import com.qding.park.common.utils.DateUtils;
import com.qding.park.manager.pojo.ap.ApSyncPageInfo;
import com.qding.park.manager.pojo.ap.ApUserCarInfo;
import com.qding.park.target.common.AdapterParam;
import com.qding.park.target.common.adapter.CarAdapter;
import com.qding.park.target.common.entity.AdCarInfo;

//@Component("bsg.carAdapter")
public class CarAdapterImpl extends AdapterParam implements CarAdapter {
	
	private static final Log _log = LogFactory.getLog(CarAdapterImpl.class);

	// private CarAdapter carAdapter;
	//
	// public CarAdapterImpl(CarAdapter carAdapter){
	// this.carAdapter=carAdapter;
	// }

	public CarAdapterImpl(String url) {
		this.setAdapterUrl(url);
	}

	@Override
	public AdCarInfo getMonthCardInfo(String parkId, String carNum) throws AdapterException, NetWorkException {

		String url = this.getAdapterUrl();
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("clientID", parkId);
		jsonObj.put("cardCode", 19);
		jsonObj.put("plateNo", carNum);
		jsonObj.put("flag", "1");
		Map<String, String> params = new HashMap<String, String>();
		params.put("UserID", "110");
//		params.put("RequestFun", ConstantFunction.Parking_GetMonthCard);
		params.put("RequestData", jsonObj.toJSONString());
		params.put("Sign", "ddd");
		try {
	//		_log.info("adapter request:"+params);
		//	String result = HttpUtil.doPost(this.getAdapterUrl(), params);
			//_log.info("adapter response:"+result);
		//	java.io.Reader in = new StringReader(result);
	//		Document doc=doc = (new SAXBuilder()).build(in);

//			String temp = doc.getRootElement().getValue();
//			in.close();
	//		ResponseMsg repmsg = JSONObject.parseObject(temp, ResponseMsg.class);
//			String errorCode = repmsg.getErrorCode();
	//		if (!ErrorCodeEnum.SUCCESS.getCode().equals(errorCode)) {
	//			throw new AdapterException(AdapterException.TypeEnum.EXCEPTION_ADAPTER_FAIL.getId(), null,
		//				ExceptionMessage.createExceptionMessage(
	//							AdapterException.TypeEnum.EXCEPTION_ADAPTER_FAIL.getDesc(), "",
	//							ConstantFunction.Parking_MonthlyFee + " adpater处理出错 "));
	//		}
	//		JSONObject data = (JSONObject) repmsg.getResult();
		    AdCarInfo apUserCarInfo = new AdCarInfo();
			apUserCarInfo.setCharge(true);
			apUserCarInfo.setExpireDate(DateUtils.parseDate("20160910", DateUtils.DATE_SHORT_DATEONLY));
			return apUserCarInfo;
		} 
	//	catch (AdapterException e) {
//			throw e;
//		} catch (NetWorkException e) {
//			throw e;
//		}
		catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
//
//	@Override
//	public ApSyncPageInfo listUserCar(String parkCode, String sync_ID) {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public List<ApUserCarInfo> allUserCar(String parkCode) throws AdapterException, NetWorkException {
//		// TODO Auto-generated method stub
//		return null;
//	}

}
